package com.lanou3g.baidumusic.main.musicfragment.videofragment;


import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lanou3g.baidumusic.R;
import com.lanou3g.baidumusic.main.mainactivity.BaseFragment;
import com.lanou3g.baidumusic.main.tools.NetResultInterface;
import com.lanou3g.baidumusic.main.tools.NetWorkInstance;

/**
 * A simple {@link Fragment} subclass.
 */
public class VideoFragment extends BaseFragment {

    private String urlStrsHot = "http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.9.9.3&channel=xiaomi&operator=1&provider=11%2C12&method=baidu.ting.mv.searchMV&format=json&order=1&page_num=1&page_size=20&query=全部" ;
    private RecyclerView recyclerView;
    private VideoAdapter adapter ;
    private TextView hotTv ;
    private TextView newTv ;


    public VideoFragment() {
        // Required empty public constructor
    }


    @Override
    public int setLayout() {
        return R.layout.fragment_video;
    }

    @Override
    public void initView(View view) {

        recyclerView = (RecyclerView) view.findViewById(R.id.fragment_video_rv_rv);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext() , 2 ,LinearLayoutManager.VERTICAL,false) ;
        recyclerView.setLayoutManager(gridLayoutManager);

    }

    @Override
    public void initData() {

        adapter = new VideoAdapter(getContext());
        recyclerView.setAdapter(adapter);

        getHotData();






    }


    //左边最热数据
    private void getHotData() {
        NetWorkInstance.getInstance().netRequest(urlStrsHot, new NetResultInterface() {
            //当网络请求成功了,自动调用此方法
            @Override
            public void sucess(String str) {
//                Log.d("success", str);

                //gson解析
                Gson gson = new Gson();
                //解析后的数据存于homeEntity中
                VideoBean songListBean = gson.fromJson(str , VideoBean.class);
//                homeEntity.getData().getItems().get(1).getIntroduction();
                adapter.setVideoBean(songListBean);

            }
            //网络请求失败了,自动调用次方法
            @Override
            public void faile(String str) {
                Log.d("faile" + "", str);
            }
        });
    }




}
